﻿using B.S.DataBase.MyProject.Domain.wdx;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
<<<<<<<< HEAD:MedicalPCTerminal.Read.API/Appcation/CommandHandlers/BasicSettingsCommandHandler/GetIndexDefineCommandHandler.cs
using MedicalPCTerminal.Read.API.Appcation.Commands.BasicSettingsCommand;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.BasicSettingsCommandHandler
========
using MedicalPCTerminal.Read.API.Appcation.Commands.基础设置;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.基础设置
>>>>>>>> parent of fe317f5 (修改命名空间):MedicalPCTerminal.Read.API/Appcation/CommandHandlers/基础设置/GetIndexDefineCommandHandler.cs
{
    public class GetIndexDefineCommandHandler : IRequestHandler<GetIndexDefineCommand, APIResult<List<IndexDefine>>>
    {

        /// <summary>
        /// SqlSugar
        /// </summary>
        private readonly SqlSugarContext sqlSugar;
        /// <summary>
        /// 构造方法
        /// </summary>
        public GetIndexDefineCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }
        public Task<APIResult<List<IndexDefine>>> Handle(GetIndexDefineCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<IndexDefine>> result = new APIResult<List<IndexDefine>>();
                var list = sqlSugar.db.Queryable<IndexDefine>().OrderByDescending(x => x.CreateTime); ;
                if (request.IndexClass_Id != null && request.IndexClass_Id != 0) { list = list.Where(x => x.IndexClass_Id == request.IndexClass_Id); }
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = list.ToList();
                return Task.FromResult(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
